/*************************************************************************
 *  Copyright © 2023-2030 Administrator. All rights reserved.
 *------------------------------------------------------------------------
 *  文件：ComponentsIgnoreList.cs
 *  作者：Administrator
 *  日期：2024/7/4 16:56:26
 *  公司：Fxb
 *  项目：com.fxb.copypastecomponents
 *  功能：Nothing
*************************************************************************/

using UnityEngine;
using System.Collections.Generic;
using System;

namespace CopyPasteComponents.Editor
{
    [CreateAssetMenu(fileName = "ComponentsIgnoreList", menuName = "ScriptableObjects/ComponentsIgnoreList", order = 1)]
	public class ComponentsIgnoreList : ScriptableObject
	{
        [HideInInspector]
        public bool isInit;

        /// <summary>
        /// 添加默认的忽略列表组件
        /// </summary>
        private List<Type> autoIgnoreList = new List<Type>()
        { 
            typeof(Transform),
            typeof(RectTransform),
            typeof(MeshFilter),
            typeof(MeshRenderer),
        };

        public List<string> IgnoreList = new List<string>();

        private void OnEnable()
        {
            if (isInit) return;
            foreach (var type in autoIgnoreList) {
                AddType(type.AssemblyQualifiedName);
            }
        }

        public List<Type> GetTypes()
        {
            List<Type> IgnoreTypeList = new List<Type>();
            foreach (var item in IgnoreList)
            {
                var type = Type.GetType(item);
                if (type != null)
                    IgnoreTypeList.Add(type);
            }
            return IgnoreTypeList;
        }

        public void AddType(string type)
        { 
            if(!IgnoreList.Contains(type))
                IgnoreList.Add(type);
        }

        public void RemoveType(string type)
        {
            if (IgnoreList.Contains(type))
                IgnoreList.Remove(type);
        }
    }
}

